#!bin/sh

base_path=$(cd "$(dirname "$0")"; pwd)
file_path=$base_path/include/protocol
file_name=$*

rm -f $base_path/server/*.h *.cc *.cpp Makefile *.conf
rm -f $base_path/client/*.h *.cc *.cpp Makefile *.conf

if [ ! $file_name ] 
then
	echo -e "\033[31m Failed passed argument!!! NULL \033[0m\n"
	exit 2
fi

# rpc server conf file build
$base_path/bin/phxrpc_pb2server -I $base_path/include -I $base_path/include/protocol -f $file_name -d $base_path/server

# .proto file code bulid
$base_path/bin/protoc -I=$file_path --cpp_out=$base_path/server $file_path/$file_name
$base_path/bin/protoc -I=$file_path --cpp_out=$base_path/client $file_path/$file_name

# rpc service code build
$base_path/bin/phxrpc_pb2service -I $base_path/include -I $base_path/include/protocol -f $file_name -d $base_path/server

# rpc client code build
$base_path/bin/phxrpc_pb2client -I $base_path/include -I $base_path/include/protocol -f $file_name -d $base_path/client
#$base_path/bin/phxrpc_pb2tool -I $base_path/include -I $base_path/include/protocol -f $file_name -d $base_path/client		//本人采用自己编写的client的客户端启动程序 如需按phxrpc原标准 请自行配置

rm -f $base_path/server/Makefile
mv $base_path/server/*.conf $base_path/conf
mv $base_path/client/*.conf $base_path/conf

echo -e "\033[32m SUCCESS \033[0m\n"
exit 0



